<template>
  <DialogAntD ref="checkDialog"
              :not-allowed="notAllowed"
              :attrs="{
                title: '请选择机构',
                type: 'user'
              }"
              :data-list.sync="dataList"
              type="user"
              :pro="pro">
  </DialogAntD>
</template>

<script>

import DialogAntD from './components/DialogAntD.vue'
import unitUserMixins from './mixins/unitUserMixins'
import PropTypes from '@zh/common-utils/prop-types'

import { getUnitAndUserListByParentId, getTreeUnitUsersByUserIds, getCrumbsByTopUnit } from '../api/select'

export default {
  name: 'ZUserPicker',
  components: { DialogAntD },
  mixins: [unitUserMixins],
  props: {
    notAllowed: PropTypes.array.def([])
  },
  data () {
    return {

    }
  },
  created () {
    this.loadNode()
  },
  methods: {
    loadNode () {
      this.listLoading = true
      getUnitAndUserListByParentId(this.topUnitId, this.cantianSelf, this.isIncludChildren).then((data) => {
        if (data) {
          const userList = data.filter(item => {
            return item.type == 2
          })
          const unitList = data.filter(item => {
            return item.type == 1
          })
          const otherList = data.filter(item => {
            return item.type != 1 && item.type != 2
          })
          const List = [...userList, ...unitList, ...otherList]
          this.dataList = []
          let labelDataList = {}
          List.forEach((item) => {
            if (item.type == 1) {
              item.id = this.userIdFlag + item.id
            }
            this.dataList.push(item.id)
            labelDataList[item.id] = item
          })
          this.labelDataList = { ...this.labelDataList, ...labelDataList }
          this.listLoading = false
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>